import json
from django.http import JsonResponse
from django.views import View
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
import requests

@method_decorator(csrf_exempt, name='dispatch')
class AICallView(View):
    def post(self, request, *args, **kwargs):
        content = json.loads(request.body).get('content')
        print(content)
        response = requests.post(
            "http://64.23.226.86:11434/api/generate",
            json={"model": "deepseek-r1:1.5b", "prompt": content, "stream": False}
        )
        data = response.json()["response"]
        print(data)

        return JsonResponse({'message': 'AI response received', 'data': data, 'code': 200}, status=200)
